<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>

<head>
    <base href="${pageContext.request.contextPath}/"/>
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="view/bootstrap-3.3.5/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="view/bootstrapvalidator/css/bootstrapValidator.css"/>
    <script charset="utf-8" src="view/jquery/jquery-1.10.2.min.js"></script>
    <script charset="utf-8" src="view/bootstrap-3.3.5/js/bootstrap.js"></script>
    <script charset="utf-8" src="view/bootstrapvalidator/js/bootstrapValidator.js"></script>

</head>
<body>


<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">编辑员工信息</h4>
    </div>

    <div class="panel-body">
        <form action="emp/editEmp" id="myform" method="post"
              class="form-horizontal" role="form">
            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="empName" class="col-md-4 control-label">员工名称</label>
                    <div class="col-md-8">
                        <input type="hidden" id="oid" name="oid" value="${emp.oid }">
                        <input type="text" id="empName" name="empName"
                               class="form-control" placeholder="请输入员工名称"
                               value="${emp.empName }">
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="deptid" class="col-md-4 control-label">所属部门</label>
                    <div class="col-md-8">
                        <select name="deptid" class="form-control" id="deptid">
                            <option value="">--请选择--</option>
                            <c:forEach items="${listDept }" var="d">
                                <option value="${d.oid }"
                                    ${d.oid==emp.deptid?"selected":"" }>${d.deptName }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="sex" class="col-md-4 control-label">员工性别</label>
                    <div class="col-md-8">
                        <input type="radio" name="sex" ${emp.sex=="M"?"checked":"" } value="M">男
                        &nbsp;&nbsp;&nbsp;
                        <input type="radio" name="sex" ${emp.sex=="F"?"checked":"" } value="F">女
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="jobid" class="col-md-4 control-label">员工职位</label>
                    <div class="col-md-8">
                        <select name="jobid" class="form-control" id="jobid">
                            <option value="">--请选择--</option>
                            <option value="${emp.jobid }" selected="selected">${emp.basic.name }</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="phone" class="col-md-4 control-label">员工电话</label>
                    <div class="col-md-8">
                        <input type="text" id="phone" name="phone" class="form-control"
                               placeholder="请输入员工电话" value="${emp.phone }">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="school" class="col-md-4 control-label">毕业学校</label>
                    <div class="col-md-8">
                        <input type="text" id="school" name="school"
                               class="form-control" placeholder="请输入员工毕业学校"
                               value="${emp.school }">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="degree" class="col-md-4 control-label">员工学历</label>
                    <div class="col-md-8">
                        <select name="degree" class="form-control" id="degree">
                            <option value="">--请选择--</option>
                            <c:forEach items="${listDegree }" var="d">
                                <option value="${d.oid }"
                                    ${d.oid==emp.degree?"selected":"" }>${d.name }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>


            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="major" class="col-md-4 control-label">所学专业</label>
                    <div class="col-md-8">
                        <input type="text" id="major" name="major"
                               class="form-control" placeholder="请输入员工所学专业"
                               value="${emp.major }">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="birthday" class="col-md-4 control-label">员工生日</label>
                    <div class="col-md-8">
                        <input type="date" id="birthday" name="birthday"
                               class="form-control" placeholder="请输入员工生日"
                               value="<fmt:formatDate value="${emp.birthday}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                        <input type="hidden" name="state" value="Y">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <hr>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="username" class="col-md-4 control-label">登录账号</label>
                    <div class="col-md-8">
                        <input type="text" id="username" name="username"
                               class="form-control" placeholder="请输入登录账号"
                               value="${emp.account.username }">
                        <input type="hidden" id="aid" name="aid" value="${emp.account.aid }">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="password" class="col-md-4 control-label">登录密码</label>
                    <div class="col-md-8">
                        <input type="password" id="password" name="password"
                               class="form-control" placeholder="请输入登录密码"
                               value="${emp.account.password }">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <hr>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="workDate" class="col-md-4 control-label">参加工作时间</label>
                    <div class="col-md-8">
                        <input type="date" id="workDate" name="workDate"
                               class="form-control" value="<fmt:formatDate value="${emp.jobinfo.workDate}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                        <input type="hidden" id="empid" name="empid" value="${emp.jobinfo.empid }">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="joinDate" class="col-md-4 control-label">加入公司时间</label>
                    <div class="col-md-8">
                        <input type="date" id="joinDate" name="joinDate"
                               class="form-control" value="<fmt:formatDate value="${emp.jobinfo.joinDate}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="contractStart" class="col-md-4 control-label">合同开始时间</label>
                    <div class="col-md-8">
                        <input type="date" id="contractStart" name="contractStart"
                               class="form-control" value="<fmt:formatDate value="${emp.jobinfo.contractStart}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="contractEnd" class="col-md-4 control-label">合同结束时间</label>
                    <div class="col-md-8">
                        <input type="date" id="contractEnd" name="contractEnd"
                               class="form-control" value="<fmt:formatDate value="${emp.jobinfo.contractEnd}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="fileDate" class="col-md-4 control-label">调入档案时间</label>
                    <div class="col-md-8">
                        <input type="date" id="fileDate" name="fileDate"
                               class="form-control" value="<fmt:formatDate value="${emp.jobinfo.fileDate}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="assureDate" class="col-md-4 control-label">担保签订时间</label>
                    <div class="col-md-8">
                        <input type="date" id="assureDate" name="assureDate"
                               class="form-control" value="<fmt:formatDate value="${emp.jobinfo.assureDate}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                    </div>
                </div>
            </div>


            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="secretDate" class="col-md-4 control-label">保密协议签订时间</label>
                    <div class="col-md-8">
                        <input type="date" id="secretDate" name="secretDate"
                               class="form-control" value="<fmt:formatDate value="${emp.jobinfo.secretDate}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <hr>
                </div>
            </div>

            <div id="exps">
                <c:forEach items="${emp.expriences }" var="exp">
                    <div>
                        <div class="col-md-12">
                            <div align="center">
                                <label>工作经历</label><BR><BR>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group col-md-6">
                                <label for="startDate" class="col-md-4 control-label">开始时间</label>
                                <div class="col-md-8">
                                    <input type="date" name="startDate" class="form-control" placeholder="请输入开始时间"
                                           value="<fmt:formatDate value="${exp.startDate}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                                    <input type="hidden" name="expoid" value="${exp.oid }">
                                    <input type="hidden" name="empid" value="${exp.empid }">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="endDate" class="col-md-4 control-label">结束时间</label>
                                <div class="col-md-8">
                                    <input type="date" name="endDate" class="form-control" placeholder="请输入结束时间"
                                           value="<fmt:formatDate value="${exp.endDate}" pattern='yyyy-MM-dd'></fmt:formatDate>">
                                </div>
                            </div>
                        </div>

                        <div class="col-md-12">
                            <div class="form-group col-md-6">
                                <label for="companyName" class="col-md-4 control-label">所在公司</label>
                                <div class="col-md-8">
                                    <input type="text" name="companyName" class="form-control" placeholder="请输入所在公司"
                                           value="${exp.companyName}">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="deptName" class="col-md-4 control-label">所在部门</label>
                                <div class="col-md-8">
                                    <input type="text" name="deptName" class="form-control" placeholder="请输入所在部门"
                                           value="${exp.deptName}">
                                </div>
                            </div>
                        </div>

                        <div class="col-md-12">
                            <div class="form-group col-md-6">
                                <label for="jobName" class="col-md-4 control-label">所在职位</label>
                                <div class="col-md-8">
                                    <input type="text" name="jobName" class="form-control" placeholder="请输入所在职位"
                                           value="${exp.jobName}">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="proofer" class="col-md-4 control-label">证明人</label>
                                <div class="col-md-8">
                                    <input type="text" name="proofer" class="form-control" placeholder="请输入证明人"
                                           value="${exp.proofer}">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group col-md-6">
                                <label for="description" class="col-md-4 control-label">工作描述</label>
                                <div class="col-md-8">
										<textarea class="form-control" id="description"
                                                  name="description" rows="5"
                                                  placeholder="请输入工作描述介绍">${exp.description}</textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="expphone" class="col-md-4 control-label">证明人电话</label>
                                <div class="col-md-8">
                                    <input type="text" name="expphone" class="form-control" placeholder="请输入证明人电话"
                                           value="${exp.phone}">
                                    <BR>
                                    <input type="button" onclick="deteleExp(this)" class="btn btn-danger"
                                           value="删除此工作经历">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group col-md-12">
                                <hr>
                            </div>
                        </div>
                    </div>
                </c:forEach>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <div class="col-md-10  col-md-offset-2">
                        <a type="button" href="javascript:history.back()" class="btn btn-info">返回</a>
                        <button type="button" id="addExprience" class="btn btn-success">添加工作经历</button>
                        <button type="submit" id="editdeptbtn" class="btn btn-success">提交信息</button>
                        <button type="reset" id="resetbtn" class="btn btn-default">取消操作</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- 工作经历模板 -->
<div id="expdemo" style="display: none;">
    <div>
        <div class="col-md-12">
            <div align="center">
                <label>工作经历</label><BR><BR>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group col-md-6">
                <label for="startDate" class="col-md-4 control-label">开始时间</label>
                <div class="col-md-8">
                    <input type="date" id="startDate" name="startDate" class="form-control" placeholder="请输入开始时间">
                </div>
            </div>
            <div class="form-group col-md-6">
                <label for="endDate" class="col-md-4 control-label">结束时间</label>
                <div class="col-md-8">
                    <input type="date" name="endDate" class="form-control" placeholder="请输入结束时间">
                </div>
            </div>
        </div>

        <div class="col-md-12">
            <div class="form-group col-md-6">
                <label for="companyName" class="col-md-4 control-label">所在公司</label>
                <div class="col-md-8">
                    <input type="text" name="companyName" class="form-control" placeholder="请输入所在公司" value="">
                </div>
            </div>
            <div class="form-group col-md-6">
                <label for="deptName" class="col-md-4 control-label">所在部门</label>
                <div class="col-md-8">
                    <input type="text" name="deptName" class="form-control" placeholder="请输入所在部门" value="">
                </div>
            </div>
        </div>

        <div class="col-md-12">
            <div class="form-group col-md-6">
                <label for="jobName" class="col-md-4 control-label">所在职位</label>
                <div class="col-md-8">
                    <input type="text" name="jobName" class="form-control" placeholder="请输入所在职位" value="">
                </div>
            </div>
            <div class="form-group col-md-6">
                <label for="proofer" class="col-md-4 control-label">证明人</label>
                <div class="col-md-8">
                    <input type="text" name="proofer" class="form-control" placeholder="请输入证明人">
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group col-md-6">
                <label for="description" class="col-md-4 control-label">工作描述</label>
                <div class="col-md-8">
						<textarea class="form-control" id="description"
                                  name="description" rows="5" placeholder="请输入工作描述介绍"></textarea>
                </div>
            </div>
            <div class="form-group col-md-6">
                <label for="expphone" class="col-md-4 control-label">证明人电话</label>
                <div class="col-md-8">
                    <input type="text" name="expphone" class="form-control" placeholder="请输入证明人电话">
                    <BR>
                    <input type="button" onclick="deteleExp(this)" class="btn btn-danger" value="删除此工作经历">
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group col-md-12">
                <hr>
            </div>
        </div>
    </div>
</div>

<%@include file="../modal/selectemp.jsp" %>
<script type="text/javascript">
    function setempvalue(eid, empName) {
        $("#manager").val(eid);
        $("#managername").val(empName);
    }
</script>
</body>


<script type="text/javascript">
    function deteleExp(o) {
        $(o).parent().parent().parent().parent().remove();
    }

    $(document).ready(function () {

        $("#deptid").change(function () {
            if (this.value == "") {
                $("#jobid")[0].options.length = 1;
                return;
            }
            $.getJSON("dept/listDeptJobUseSelect", {deptid: $("#deptid").val()}, function (listjob) {
                var job = $("#jobid")[0];
                job.options.length = 1;
                for (var i = 0; i < listjob.length; i++) {
                    var job1 = listjob[i];
                    job.options.add(new Option(job1.name, job1.oid));
                }
            }).complete(function (xhr) {
                if (xhr.status == "403") {//没有权限
                    document.location.href = xhr.getResponseHeader("url");
                } else if (xhr.status != "200") {
                    console.log("服务器错误!");
                }
            });
        });

        $("#addExprience").click(function () {
            $("#exps").append($("#expdemo").html());
            $('#myform').bootstrapValidator('addField', 'proofer', {
                validators: {
                    notEmpty: {/*非空提示*/
                        message: '证明人不能为空'
                    },
                    stringLength: {
                        min: 2,
                        max: 10,
                        message: '证明人名称长度需在2-10位'
                    }

                }
            });
            $('#myform').bootstrapValidator('addField', 'expphone', {
                validators: {
                    notEmpty: {/*非空提示*/
                        message: '证明人电话不能为空'
                    },
                    regexp: {
                        regexp: /^(^(\d{3,4}-)?\d{7,8})$|^((1[0-9][0-9]\d{8}$))$/,
                        message: '电话格式不正确'
                    }
                }
            });
            $('#myform').bootstrapValidator('addField', 'startDate', {
                validators: {
                    notEmpty: {/*非空提示*/
                        message: '工作开始时间不能为空'
                    },
                    date: {
                        format: 'YYYY-MM-DD',
                        message: '员工生日格式不正确'
                    }
                }
            });
            $('#myform').bootstrapValidator('addField', 'endDate', {
                validators: {
                    notEmpty: {/*非空提示*/
                        message: '工作结束时间不能为空'
                    },
                    date: {
                        format: 'YYYY-MM-DD',
                        message: '员工生日格式不正确'
                    }
                }
            });
        });

        $("#myform").bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {/*input状态样式图片*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                empName: {
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '员工姓名不能为空'

                        },
                        stringLength: {
                            min: 2,
                            max: 10,
                            message: '员工名称长度需在2-10位'
                        }
                    }
                },
                sex: {
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '请选择员工性别'
                        }
                    }
                },
                phone: {
                    validators: {
                        regexp: {
                            regexp: /^(^(\d{3,4}-)?\d{7,8})$|^((1[0-9][0-9]\d{8}$))$/,
                            message: '电话格式不正确'
                        }
                    }
                },
                email: {
                    validators: {
                        emailAddress: {
                            message: 'E-mail格式不正确'
                        }
                    }
                },
                school: {
                    validators: {
                        stringLength: {
                            max: 10,
                            message: '学校名称输入过长'
                        }
                    }
                },
                major: {
                    validators: {
                        stringLength: {
                            max: 20,
                            message: '专业名称输入过长'
                        }
                    }
                },
                birthday: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '员工生日格式不正确'
                        }
                    }
                },
                username: {
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '登录账号不能为空'
                        },
                        stringLength: {
                            min: 3,
                            max: 20,
                            message: '登录账号长度需在3-20位'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z][a-zA-Z0-9]{2,19}$/,
                            message: '登录账号格式:字母和数字组成,首字母必须是字母'
                        },
                        remote: {
                            url: "emp/checkUsername",
                            delay: 1000,
                            type: 'post',
                            message: '账号已存在!',
                            data: function (validator) {
                                return {
                                    'username': $("#username").val(),
                                    'aid': $("#aid").val(),
                                };
                            }
                        }
                    }
                },
                password: {
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '登录密码不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 20,
                            message: '登录密码长度需在6-20位'
                        }
                    }
                },
                workDate: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '日期格式不正确'
                        }
                    }
                },
                joinDate: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '日期格式不正确'
                        }
                    }
                },
                fileDate: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '日期格式不正确'
                        }
                    }
                },
                contractStart: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '日期格式不正确'
                        }
                    }
                },
                contractEnd: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '日期格式不正确'
                        }
                    }
                },
                assureDate: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '日期格式不正确'
                        }
                    }
                },
                secretDate: {
                    validators: {
                        date: {
                            format: 'YYYY-MM-DD',
                            message: '日期格式不正确'
                        }
                    }
                }
            },
            submitHandler: function (validator, form, submitButton) {
                validator.defaultSubmit();
            }
        });


        $("#resetbtn").click(function () {
            $("#myform").data("bootstrapValidator").resetForm();
        });
    });


</script>
</html>